<template>
  <section class="mailchimp-one" id="subscribe">
    <Message ref="message"/>
    <div class="container wow fadeInUp" data-wow-duration="1500ms"
         style="align-items: center;display: flex;justify-content: center;">
      <div class="block-title text-center">
        <h2 class="block-title__title">请如实填写个人信息进行报名</h2>
        <!-- /.block-title__title -->
      </div><!-- /.block-title -->
      <div class="form-container">
        <form>
          <div class="form-group">
            <input type="text" v-model="enrollmentInfo.stuNo" id="studentId" name="studentId" placeholder=" " >
            <label for="studentId">学号</label>
          </div>
          <div class="form-group">
            <input type="text" v-model="enrollmentInfo.clazz" id="class" name="class" placeholder=" " >
            <label for="class">班级</label>
          </div>
          <div class="form-group">
            <input type="text" v-model="enrollmentInfo.name" id="name" name="name" placeholder=" " >
            <label for="name">姓名</label>
          </div>
          <div class="form-group">
            <input type="tel" v-model="enrollmentInfo.phone" id="phone" name="phone" placeholder=" " >
            <label for="phone">电话</label>
          </div>
          <div class="button-container">
            <div type="submit" class="buttonDiv" @click="save()">提交信息</div>
          </div>
        </form>
      </div>
      <div class="mc-form__response"></div>
    </div><!-- /.container -->
  </section>
</template>

<script>
import apis from '../apis/apis';
import Message from './Message.vue'


export default {
  name: "Subscribe",
  components: {
    Message
  },
  data() {
    return {
      enrollmentInfo: {
        stuNo: '',
        clazz: '',
        name: '',
        phone: '',
      }
    }
  },
  methods: {
    validateEnrollmentInfo(enrollmentInfo) {
      // 验证所有字段不能为空
      if (!enrollmentInfo.stuNo || !enrollmentInfo.clazz || !enrollmentInfo.name || !enrollmentInfo.phone) {
        return {
          valid: false,
          message: '所有字段都不能为空'
        };
      }
      // 验证电话号码格式
      const phoneRegex = /^1[3-9]\d{9}$/;
      if (!phoneRegex.test(enrollmentInfo.phone)) {
        return {
          valid: false,
          message: '请输入正确的手机号码格式'
        };
      }
      return {
        valid: true,
        message: '验证通过'
      };
    },
    save() {
      const result = this.validateEnrollmentInfo(this.enrollmentInfo);
      if (result.valid) {
        apis.saveEnrollment(this.enrollmentInfo).then(res => {
          if (res.code === 0) {
            this.$refs.message.message = "报名成功！"
            this.$refs.message.type = 'success'
          } else {
            this.$refs.message.message = res.msg
            this.$refs.message.type = 'error'
          }
          this.$refs.message.show()
        })
      } else {
        this.$refs.message.message = result.message
        this.$refs.message.type = 'error'
        this.$refs.message.show()
      }
    }
  }
}
</script>

<style scoped>
.container {
  width: 100%;
  background-image: linear-gradient(40deg, #ff43c0 0%, #ffa95c 100%);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
}

.form-container {
  background: rgba(255, 255, 255, 0.9);
  padding: 30px;
  border-radius: 15px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  width: 100%;
  max-width: 900px;
  transform: translateY(0);
  transition: transform 0.3s ease;
  animation: float 3s ease-in-out infinite;
}

.form-container:hover {
  transform: translateY(-5px);
  animation-play-state: paused;
}

@keyframes float {
  0% {
    transform: translateY(0px);
  }
  50% {
    transform: translateY(-10px);
  }
  100% {
    transform: translateY(0px);
  }
}

form {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  justify-content: space-between;
}

.form-group {
  flex: 1;
  min-width: 200px;
  margin-bottom: 0;
  position: relative;
}

label {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: #999;
  font-size: 16px;
  pointer-events: none;
  transition: all 0.3s ease;
  background: transparent;
  padding: 0 5px;
}

input {
  width: 100%;
  padding: 12px;
  border: 2px solid #ddd;
  border-radius: 8px;
  font-size: 16px;
  transition: all 0.3s ease;
  background: transparent;
}

input:focus {
  border-color: #ff43c0;
  outline: none;
  box-shadow: 0 0 8px rgba(255, 67, 192, 0.2);
}

input:focus + label,
input:not(:placeholder-shown) + label {
  top: 0;
  font-size: 12px;
  color: #ff43c0;
  background: white;
  transform: translateY(-50%);
}

input::placeholder {
  color: transparent;
}

.button-container {
  width: 100%;
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
}

.buttonDiv {
  position: relative;
  width: 200px;
  height: 50px;
  background: transparent;
  border: 2px solid #ff43c0;
  border-radius: 4px;
  color: #ff43c0;
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  overflow: hidden;
  transition: all 0.3s ease;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.buttonDiv::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(40deg, #ff43c0 0%, #ffa95c 100%);
  z-index: -1;
  transform: scaleX(0);
  transform-origin: right;
  transition: transform 0.5s ease;
}

.buttonDiv:hover {
  color: white;
  border-color: transparent;
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(255, 67, 192, 0.3);
}

.buttonDiv:hover::before {
  transform: scaleX(1);
  transform-origin: left;
}

.buttonDiv:active {
  transform: translateY(1px);
}

.buttonDiv::after {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.3) 0%, transparent 60%);
  transform: scale(0);
  transition: transform 0.5s ease;
  pointer-events: none;
}

.buttonDiv:hover::after {
  transform: scale(1);
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.form-container {
  animation: fadeIn 0.8s ease-out, float 3s ease-in-out infinite;
}
</style>
